package edu.bu.met683.TravelDroid;

import java.util.List;
import edu.bu.met683.TravelDroid.data.*;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class TourListAdapter extends BaseAdapter {
	//private properties
	private final Context context;
	private final List<Tour> tours;

	//constructors
	public TourListAdapter(final Context context, final List<Tour> tours) {
		super();
		this.context = context;
		this.tours = tours;
	}
	
	//public methods
	public int getCount() {
		return this.tours.size();
	}

	public Object getItem(int position) {
		return this.tours.get(position);
	}

	public long getItemId(final int position) {
		return (long)position;
	}

	public View getView(final int position, final View convertView, final ViewGroup parent) 
	{
		try
		{
			Tour tour = this.tours.get(position);
			return new TourListView(context, tour.getName(), tour.getLength(), tour.getDescription(), tour.getProximity());
		}
		catch(Exception e)
		{
			Log.e("Error in TourListAdapter", e.getMessage());
			return null;
		}
	}
	
	

}
